from sklearn.ensemble import GradientBoostingClassifier
from sklearn.neural_network import MLPClassifier
from sklearn.ensemble import AdaBoostClassifier
from xgboost import XGBClassifier
import time

class Classifier(object):
    CLASSIFIER = {
        "GBDT": GradientBoostingClassifier(n_estimators=150, learning_rate=1.0, max_depth=1, random_state=0),
        "MLP": MLPClassifier(solver="sgd", alpha=1e-5, hidden_layer_sizes=[1024, 512, 64, 6], random_state=1, verbose=True),
        "AdaBoost": AdaBoostClassifier(n_estimators=500, learning_rate=1.0, random_state=0),
        "XGBoost": XGBClassifier(learning_rate=0.1, n_estimators=150, max_depth=6, min_child_weight=1, gamma=0., random_state=0),
    }
    
    def __init__(self, *clfs):
        self.classifiers = clfs

    def fit(self, x, y):
        elapsed = {}
        for clf in self.classifiers:
            print(f"{clf} training")  
            start = time.time()          
            self.CLASSIFIER[clf].fit(x, y)
            end = time.time()
            elapsed[clf] = end - start
            print(f"{clf} Done")
        return elapsed

    def score(self, x, y):
        acc_rate = {}
        for clf in self.classifiers:
            acc = self.CLASSIFIER[clf].score(x, y)
            acc_rate[clf] = acc
            print(f"{clf} acc: {acc}")
        return acc_rate

    def predict(self, x, *clfs):
        out = {}
        for clf in clfs:
            y = self.CLASSIFIER[clf].predict(x)
            out[clf] = y
        return out

    def save_clf(self):
        pass